//===============================================================================
// Microsoft patterns & practices
// Mobile Client Software Factory - July 2006
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using System.CodeDom.Compiler;
using System.ComponentModel;

namespace Microsoft.Practices.ObjectBuilder.ObGen
{
	/// <summary>
	/// Provides programmatic access to the ObjectBuilder configuration section.
	/// </summary>
	public class ObjectBuilderSection : SerializableConfigurationSection
	{
		public const string SectionName = "objectBuilder";
		const string PropertyCodeProvider = "codeProvider";
		const string PropertyEmitSources = "emitSources";
		const string PropertyDebugSymbols = "debugSymbols";
		const string PropertyCompilerOptions = "compilerOptions";

		[ConfigurationProperty(PropertyCodeProvider, IsRequired=true)]
		[TypeConverter(typeof(AssemblyQualifiedTypeNameConverter))]
		[SubclassTypeValidator(typeof(CodeDomProvider))]
		public Type CodeProvider
		{
			get { return (Type)this[PropertyCodeProvider]; }
			set { this[PropertyCodeProvider] = value; }
		}

		[ConfigurationProperty(PropertyCompilerOptions, DefaultValue = "")]
		public string CompilerOptions
		{
			get { return (string)this[PropertyCompilerOptions]; }
			set { this[PropertyCompilerOptions] = value; }
		}

		[ConfigurationProperty(PropertyEmitSources, DefaultValue = false)]
		public bool EmitSources
		{
			get { return (bool)this[PropertyEmitSources]; }
			set { this[PropertyEmitSources] = value; }
		}

		[ConfigurationProperty(PropertyDebugSymbols, DefaultValue = false)]
		public bool DebugSymbols
		{
			get { return (bool)this[PropertyDebugSymbols]; }
			set { this[PropertyDebugSymbols] = value; }
		}

		[ConfigurationProperty("policyGenerators")]
		public NameTypeConfigurationElementCollection<PolicyGeneratorFactoryElement> PolicyGenerators
		{
			get { return (NameTypeConfigurationElementCollection<PolicyGeneratorFactoryElement>)this["policyGenerators"]; }
		}

		public static ObjectBuilderSection GetConfigurationSection()
		{
			return (ObjectBuilderSection)ConfigurationManager.GetSection(SectionName);
		}
	}
}
